package com.vote.web.controller.business;

import com.vote.business.domain.vo.CalculateCoreVO;
import com.vote.business.domain.vo.HotVoteTopVO;
import com.vote.business.domain.vo.OngoingVoteVO;
import com.vote.business.domain.vo.TotalParticipationVO;
import com.vote.business.service.IVoteDashboardService;
import com.vote.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/business/dashboard")
public class VoteDashboardController {

    @Autowired
    private IVoteDashboardService voteDashboardService;

    /**
     * 获取所有投票
     * @return
     */
    @GetMapping("/coreStats")
    public AjaxResult getCoreStats(){
        CalculateCoreVO stats = voteDashboardService.calculateCoreStats();
        return AjaxResult.success(stats);
    }
    // 获取进行中投票统计
    @GetMapping("/ongoingVote")
    public AjaxResult getOngoingVote() {
        OngoingVoteVO stats = voteDashboardService.getOngoingVoteStats();
        return AjaxResult.success(stats);
    }
    // 获取总参与人次统计
    @GetMapping("/totalParticipation")
    public AjaxResult getTotalParticipation() {
        TotalParticipationVO stats = voteDashboardService.getTotalParticipation();
        return AjaxResult.success(stats);
    }
    @GetMapping("/hotVoteTop1")
    public AjaxResult getHotVoteTop1() {
        return AjaxResult.success(voteDashboardService.selectHotVoteTop1());
    }

    @GetMapping("/voteStatus")
    public AjaxResult getVoteStatus() {
        return AjaxResult.success(voteDashboardService.getVoteStatusDistribution());
    }

    @GetMapping("/hotVoteTop5")
    public AjaxResult getHotActivityTop5() {
        return AjaxResult.success(voteDashboardService.selectHotVoteTop5());
    }

    @GetMapping("/voteTrend30d")
    public AjaxResult getActivityTrend30d() {
        return AjaxResult.success(voteDashboardService.getVoteCreateTrend30d());
    }

    @GetMapping("/voteOptionRatio")
    public AjaxResult getActivityOptionRatio(Long voteId) {
        HotVoteTopVO hotVoteTopVO =voteDashboardService.selectHotVoteTop1();
        return AjaxResult.success(voteDashboardService.getVoteOptionRatio(hotVoteTopVO.getVoteId()));
    }
}
